package com.example.xlmkotlinwanandroid.model.repository

import com.example.xlmkotlinwanandroid.base.BaseRepository
import com.example.xlmkotlinwanandroid.ext.await
import com.example.xlmkotlinwanandroid.model.bean.ArticleBean
import com.example.xlmkotlinwanandroid.model.bean.BannerBean
import com.example.xlmkotlinwanandroid.network.ApiService
import com.example.xlmkotlinwanandroid.network.ServiceCreator
import androidx.lifecycle.MutableLiveData
import com.example.xlmkotlinwanandroid.model.bean.ProjectCategoryBean
import com.example.xlmkotlinwanandroid.network.Network
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext


object Repository : BaseRepository() {

    //网络请求获取数据
    suspend fun getHomeViewModel(pageNo: Int): List<ArticleBean>? {
        val articleList = Network.getArticleList(pageNo)
        return if (articleList.errorCode == 0) {
            articleList.data?.datas
        } else {
            null
        }
    }

    //请求banner
    suspend fun getBannerData(): ArrayList<BannerBean>? {
        //获取到数据
        val bannerList = Network.getBannerList()
        //对数据进行脱壳
        return bannerList.data
    }

    //请求项目类别
    suspend fun getProjectCategory(): ArrayList<ProjectCategoryBean>? {
        //获取到数据
        val categoryList = Network.getProjectCategory()
        //对数据进行脱壳
        return categoryList.data
    }
    //根据项目类别请求数据
    suspend fun getProjectArticleByType(pageNo: Int, cid: Int):ArrayList<ArticleBean>?{
        val projectArticleList = Network.getProjectArticleByType(pageNo,cid)
        return projectArticleList.data?.datas
    }
}